<?php
namespace app\admin\controller;

use think\Controller;

class Member extends Controller
{
    public function login()
    {
        $msg=null;
        if(request()->isPost())
        {
            $tel=input("post.tel");
            $safecode=cache("safecode_login_{$tel}");
            if(input("post.safecode")==$safecode)
            {
                $proxy=model("proxy");
                $data=$proxy->bytel($tel);
                session("proxy",$data);
                cache("safecode_login_{$tel}",null);
                $this->redirect("Index/index");
                return;
            }

            $msg="验证码不正确";
        }
        return view("login",array("msg"=>$msg));
    }

    public function reg(){
        return "can not open reg!";
    }

    public function sendsafecode(){
        $proxy=model("proxy");
        $tel=input("post.tel");
        $tpye=input("post.type")=="login"?"login":"reset";
        $data=$proxy->bytel($tel);
        if(empty($data))return error("手机号不存在");
        $safecode=str_pad(rand(0,999999),6,"0",STR_PAD_LEFT);
        $noticeresult=notice(array("type"=>"SMS","tpl_id"=>"31428","mobile"=>$tel,"msg"=>"#code#=$safecode"));
        cache("safecode_{$tpye}_{$tel}",$safecode,300);
        if($noticeresult) return error($noticeresult);
        return success("safecode_log_{$tpye}_{$tel}");
    }
}
